package com.jkc.xh.fragments;

import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.fragments.core.BaseFragment;
import com.jkc.xh.manager.UserManager;
import com.jkc.xh.models.BankCardModel;
import com.jkc.xh.network.RestCallBack;
import com.jkc.xh.network.models.RestError;
import com.jkc.xh.network.models.SystemHintResponse;
import com.jkc.xh.views.headview.BankCardView;
import com.jkc.xh.views.headview.BankCardView_;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;

/**
 * 付款方式
 * Created by zhangbreeze on 15/11/21.
 */
@EFragment(R.layout.fragment_pay_bank)
public class PayWayBankFragment extends BaseFragment {


    @ViewById
    LinearLayout cardContainer;
    @ViewById
    TextView hintInfo;
    @AfterViews
    public void initData() {
        addJob(UserManager.getCpmfHintConfig(new RestCallBack<SystemHintResponse>() {
            @Override
            public void success(SystemHintResponse obj) {
                hintInfo.setText(Html.fromHtml(obj.remitance_remark));
            }

            @Override
            public void failure(RestError error) {

            }
        }));
    }


    public void loadCardData(ArrayList<BankCardModel> datas) {
        cardContainer.removeAllViews();
        if (datas == null) {
            return;
        }
        for (BankCardModel model : datas) {
            cardContainer.addView(createCardView(model));
        }
    }

    private View createCardView(BankCardModel model) {
        BankCardView cardView = BankCardView_.build(getContext());
        cardView.loadInfo(model);
        return cardView;
    }
}
